﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace FBGSensorConfig
{
    public partial class FrmMain : Form
    {
        public FrmMain()
        {
            InitializeComponent();
            btnAdd.Click += new EventHandler(btnAdd_Click);
            btnCreate.Click += new EventHandler(btnAdd_Click);
            btnOpen.Click += new EventHandler(btnAdd_Click);
            btnSave.Click += new EventHandler(btnAdd_Click);

            txtNO.KeyPress += new KeyPressEventHandler(txtNO_KeyPress);
            txtWav1.KeyPress += new KeyPressEventHandler(txtNO_KeyPress);
            txtWav2.KeyPress += new KeyPressEventHandler(txtNO_KeyPress);
        }

        private Dictionary<int, jzGroup> zctMap = null;

        //private void GetMap(string mapPath, out Dictionary<int, jzGroup> map)
        //{ 
        //}

        void txtNO_KeyPress(object sender, KeyPressEventArgs e)
        {
            var txtBox = sender as ToolStripTextBox;
            //判断按键是不是要输入的类型。
            if (((int)e.KeyChar < 48 || (int)e.KeyChar > 57) && (int)e.KeyChar != 8 && (int)e.KeyChar != 46)
                e.Handled = true;

            //小数点的处理。
            if ((int)e.KeyChar == 46)                           //小数点
            {
                if (txtBox.Text.Length <= 0 ||txtBox.Name == txtNO.Name)
                    e.Handled = true;   //小数点不能在第一位
                else
                {
                    float f;
                    float oldf;
                    bool b1 = false, b2 = false;
                    b1 = float.TryParse(txtBox.Text, out oldf);
                    b2 = float.TryParse(txtBox.Text + e.KeyChar.ToString(), out f);
                    if (b2 == false)
                    {
                        if (b1 == true)
                            e.Handled = true;
                        else
                            e.Handled = false;
                    }
                }
            }


        }

        void btnAdd_Click(object sender, EventArgs e)
        {

        }
    }

    public class jzGroup
    {
        private int _No = -1;
        /// <summary>
        /// 分组号
        /// </summary>
        public int No
        {
            get { return _No; }
            set 
            {
                if (value > 255 || value < 0)
                {
                    System.Diagnostics.Debug.Assert(false, "分组号不合法，请重新输入！");
                    return;
                }
                _No = value;
            }
        }

        private double _Wav1 = 1525.0;
        /// <summary>
        /// 传感器1波长
        /// </summary>
        public double Wav1
        {
            get { return _Wav1; }
            set
            {
                if (value > 1570 || value < 1525)
                {
                    System.Diagnostics.Debug.Assert(false, "传感器波长不合法，请重新输入！");
                    return;
                }
                _Wav1 = value;
            }
        }

        private double _Wav2 = 1570.0;
        /// <summary>
        /// 传感器2波长
        /// </summary>
        public double Wav2
        {
            get { return _Wav2; }
            set 
            {
                if (value > 1570 || value < 1525)
                {
                    System.Diagnostics.Debug.Assert(false, "传感器波长不合法，请重新输入！");
                    return;
                }
                _Wav2 = value;
            }
        }
    }
}
